//
//  BlockModel.m
//  CoreGraphicsTest
//
//  Created by aewatson on 11/19/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "BlockModel.h"


@implementation BlockModel

@synthesize centerX;
@synthesize centerY;
@synthesize velocityX;
@synthesize velocityY;
@synthesize size;
@synthesize direction;
@synthesize color;
@synthesize rect;

-(id)initWithSize:(float) newSize centerX:(float) newX centerY:(float) newY direction:(DIRECTION) newDirection andColor:(COLOR) newColor {
    self = [super init];
    
    // initialize datamembers
    [self setCenterX: newX];
    [self setCenterY: newY];
    [self setSize: newSize];
    [self setDirection: newDirection];
    [self setColor: newColor];
    
    // initialize velocities
    [self setVelocityX:80]; // pixels per second
    [self setVelocityY:-80]; // pixels per second
    
    // finished initializing
    return self;
}

-(float)getLeft {
    return centerX - size / 2;
}

-(float)getTop {
    return centerY - size / 2;
}

-(float)getWidth{
    return (float) size;
}

-(float)getHeight{
    return (float) size;
}

-(COLOR) getColor {
    return color;
}

-(void) setCenterX:(float) newX andY:(float) newY {
    [self setCenterX:newX];
    [self setCenterY:newY];
}

-(void) moveByDeltaX:(float) dX andDeltaY:(float) dY {
    centerX += dX;
    centerY += dY;
}

-(void) locationAfterMilliseconds:(float) ms {
    float seconds = ms / 1000;
    NSLog(@"CenterX was %0.2f", centerX);
    centerX += direction * velocityX * seconds;
    NSLog(@"CenterX is now %0.2f", centerX);
    centerY += velocityY * seconds + 0.5 * ([GameModel getAcceleration] * (seconds * seconds));
    velocityY += [GameModel getAcceleration] * seconds;
}

@end
